package com.spring.shops.service.impl;

import com.spring.shops.dao.TzHotSearchMapper;
import com.spring.shops.model.dto.HotSearchDTO;
import com.spring.shops.model.entity.TzHotSearch;
import com.spring.shops.model.vo.PageVo;
import com.spring.shops.service.HotSearchService;
import net.sf.jsqlparser.expression.DateTimeLiteralExpression;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Service
public class HotSearchServiceImpl implements HotSearchService {
    @Resource
    private TzHotSearchMapper tzHotSearchMapper;

    @Override
    public int HotSearch(TzHotSearch t) {
        t.setRecDate(new Date());
        int i = tzHotSearchMapper.insertSelective(t);
        return i;
    }

    @Override
    public int DeleteHotSearch(Integer[] list) {
        List<Integer> list1 = Arrays.asList(list);
        int i = tzHotSearchMapper.deleteByPrimaryKeys(list1);
        return i;
    }

    @Override
    public int UpdateHotSearch(TzHotSearch tzHotSearch) {
        int i = tzHotSearchMapper.updateByPrimaryKeySelective(tzHotSearch);
        return i;
    }

    @Override
    public PageVo selectByPage(PageVo pageVo, String title, String content, int status) {
        long total = tzHotSearchMapper.selectCountHotSearch();
        pageVo.setTotal(total);
        HotSearchDTO hotSearchDTO = new HotSearchDTO();
        int size = Integer.parseInt(pageVo.getSize());
        hotSearchDTO.setContent(content);
        hotSearchDTO.setStatus(status);
        hotSearchDTO.setSize(size);
        hotSearchDTO.setTitle(title);
        int current = Integer.parseInt(pageVo.getCurrent());
        hotSearchDTO.setCurrent(current-1);
        TzHotSearch[] tzHotSearches = tzHotSearchMapper.selectByPageSearch(hotSearchDTO);
        System.out.println(tzHotSearches.length);
        pageVo.setRecords(tzHotSearches);
        return pageVo;

    }

    @Override
    public TzHotSearch selectById(int id) {
        TzHotSearch tzHotSearch = tzHotSearchMapper.selectById((long) id);
        return tzHotSearch;
    }
}
